// var request = new UrlSearch();
// $.ajax({
//     url: 'actionDispatcher.do?reqUrl=ValidateAuthorization&code=' + request.code,
//     dataType: 'json',
//     type: 'get',
//     success: function(data) { // 成功后回调
//         if (data.a === 0) {
//             alert(3);
//         } else {
//             if (data.e === '-1000010106') {
//                 window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1735aedb0ca1630f&redirect_uri=' +
//                     encodeURIComponent(window.location.href) +
//                     '&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect';
//             } else if (data.e === '-1000010158') {
// window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx1735aedb0ca1630f&redirect_uri=' +
//     encodeURIComponent('http://qdjy.ngrok.cc/valid.html') +
//     '&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect';
//             }
//         }
//     }
// });
import { education as Api } from '../../api/education';
export default {
    mounted() {
        this.$bindinit();
    },
    data() {
        return {
            domain: 'www.7fearless.com',
            // domain: '123.207.7.165',
            codes: {
                code: ''
            },
            personalid: ''
        };
    },
    methods: {
        $bindinit() {
            let getUrlStr = function(name) {
                // var personalid = '';
                var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)');
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            };
            this.codes.code = getUrlStr('code');
            if (this.codes.code !== null) {
                Api.validateAuthorization.call(this, this.codes, data => {
                    this.personalid = data.userId;
                    window.location.href = 'http://' + this.domain + '/edu/index.html#/index';
                    // window.location.href = 'http://' + this.domain + '/#/index';
                });
            }
            // let personalId = this.personalid;
        },
        $bindResize() {},
        $unBindResize() {}
        // UrlSearch() {
        //     var name, value;
        //     var str = window.location.href;
        //     var num = str.indexOf('?');
        //     str = str.substr(num + 1);
        //     var arr = str.split('&');
        //     for (var i = 0; i < arr.length; i++) {
        //         num = arr[i].indexOf('=');
        //         if (num > 0) {
        //             name = arr[i].substring(0, num);
        //             value = arr[i].substr(num + 1);
        //             this[name] = value;
        //         }
        //     }
        // }
    },
    beforeDestroy() {
        this.$unBindResize();
    }
};